﻿Imports Microsoft.VisualBasic
Imports System.Data

Namespace HensonOnline
    Public Class PhotoAlbums





    End Class

    Public Class Image
        Private _ImgId As Integer
        Private _UserId As String
        Private _Title As String
        Private _Caption As String
        Private _FilePath As String
        Private _Height As Integer
        Private _Width As Integer
        Private _IsPrivate As Boolean
        Private _Comment As String

        Public Property ImgId() As Integer
            Get
                Return _ImgId
            End Get
            Set(ByVal value As Integer)
                _ImgId = value
            End Set
        End Property

        Public Property UserId() As String
            Get
                Return _UserId
            End Get
            Set(ByVal value As String)
                _UserId = value
            End Set
        End Property

        Public Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        Public Property Caption() As String
            Get
                Return _Caption
            End Get
            Set(ByVal value As String)
                _Caption = value
            End Set
        End Property

        Public Property FilePath() As String
            Get
                Return _FilePath
            End Get
            Set(ByVal value As String)
                _FilePath = value
            End Set
        End Property

        Public Property Height() As Integer
            Get
                Return _Height
            End Get
            Set(ByVal value As Integer)
                _Height = value
            End Set
        End Property

        Public Property Width() As Integer
            Get
                Return _Width
            End Get
            Set(ByVal value As Integer)
                _Width = value
            End Set
        End Property

        Public Property IsPrivate() As Boolean
            Get
                Return _IsPrivate
            End Get
            Set(ByVal value As Boolean)
                _IsPrivate = value
            End Set
        End Property

        Public Property Comment() As String
            Get
                Return _Comment
            End Get
            Set(ByVal value As String)
                _Comment = value
            End Set
        End Property

        Private Sub PopulateDefault()
            _ImgId = 0
            _UserId = 0
            _Title = ""
            _Caption = ""
            _FilePath = ""
            _IsPrivate = False
            _Comment = ""
        End Sub

        Public Sub New()
            PopulateDefault()
        End Sub

        Public Sub New(ByVal ImgId As Integer)

        End Sub

        Public Function GetImage(ByVal ImgId As Integer, ByVal userId As Integer) As ArrayList
            Dim sql As String = "sp_getImage"
            Dim type As CommandType = CommandType.StoredProcedure
            Dim parameters As List(Of System.Data.SqlClient.SqlParameter) = New List(Of System.Data.SqlClient.SqlParameter)
            parameters.Add(New System.Data.SqlClient.SqlParameter("@UserId", userId))
            parameters.Add(New System.Data.SqlClient.SqlParameter("@ImgId", ImgId))
            Dim data As New DataAccess
            Dim propertyList As ArrayList = data.SelectSingle(sql, type, parameters.ToArray, 7)

            If propertyList.Count > 0 Then
                _ImgId = propertyList(0)
                _UserId = propertyList(1)
                _Title = propertyList(2)
                _Caption = propertyList(3)
                _FilePath = propertyList(4)
                _IsPrivate = propertyList(5)
                _Comment = propertyList(6)
            Else
                _IsPrivate = True
            End If

            Return propertyList
        End Function

        Public Function GetMyImages(ByVal userId As Integer) As ArrayList
            Dim sql As String = "SELECT * FROM Images WHERE UserId  = @UserId"
            Dim type As CommandType = CommandType.Text
            Dim parameters As List(Of System.Data.SqlClient.SqlParameter) = New List(Of System.Data.SqlClient.SqlParameter)
            parameters.Add(New System.Data.SqlClient.SqlParameter("@UserId", userId))
            Dim data As New DataAccess
            Dim imageList As ArrayList = data.SelectList(sql, type, parameters.ToArray)

            Return imageList
        End Function


        Public Function GetMyImagesRand(ByVal userId As Integer) As ArrayList
            Dim sql As String = "select TOP 200 * from images where userid = 3 order by NEWID()"
            Dim type As CommandType = CommandType.Text
            Dim parameters As List(Of System.Data.SqlClient.SqlParameter) = New List(Of System.Data.SqlClient.SqlParameter)
            parameters.Add(New System.Data.SqlClient.SqlParameter("@UserId", userId))
            Dim data As New DataAccess
            Dim imageList As ArrayList = data.SelectList(sql, type, parameters.ToArray)

            Return imageList
        End Function

    End Class
End Namespace
